<?php


/*
 * To change this template, choose Tools | Templates
* and open the template in the editor.
*/
require_once 'lib/raspuns.php';
require_once 'lib/cerere.php';

class Investitie {
	
	var $nume;
	

}

require_once ('../conexiune_bazadedate.php');

$cerere = new Cerere(array ());

if (isset ($cerere->params)) {

	$array_r = $cerere->params;
	$Investitie = new Investitie();
	
	$Investitie->nume = ($array_r->nume);
	
	$client = $_GET["client_fk"];
	//update
	$query = "INSERT INTO investitii (nume,client_fk) VALUES ('$Investitie->nume','$client')";
	$result = mysql_query($query);
	//object response
	$res = new Raspuns();
	$res->success = true;
	$res->message = "Created Record";

	//Need to Send Articol to EXTjs to be correctly viewd in grid
	$result = mysql_query("SELECT * FROM investitii where id_investitie =" . mysql_insert_id());
	$query_array = array ();
	$i = 0;
	//Iterate all Select
	while ($row = mysql_fetch_array($result)) {

		$Investitie = new Investitie();

		$Investitie->nume = $row['nume'];

		$query_array[$i] = $Investitie;
		$i++;
	}

	$res->data = $query_array;
	//print Json
	print_r($res->to_json());
} else {
	//echo "false";
	$res = new Raspuns();
	$res->success = false;
	$res->message = "Error Create record";
	$res->data = array ();
	print_r($res->to_json());
}
?>
